package Greedy;

public class _860_LemonadeChange {
    public boolean lemonadeChange(int[] bills) {
        //save the bills 5, 10 ,20
        int[] changes = new int[3];
        for (int i = 0; i < bills.length; i++) {
            if (bills[i] == 5) {
                changes[0]++;
            } else if (bills[i] == 10) {
                if (changes[0] > 0) {
                    changes[1]++;
                    changes[0]--;
                } else {
                    return false;
                }
            } else {
                if (changes[0] > 0 && changes[1] > 0) {
                    changes[2]++;
                    changes[0]--;
                    changes[1]--;
                } else if (changes[0] >= 3) {
                    changes[2]++;
                    changes[0] -= 3;
                } else {
                    return false;
                }
            }
        }
        return true;
    }
}
